<?php
/**
 * Minhlog Domain_Mapper 文章评论类
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   Domain
 * @package    Domain_DataMapper
 * @copyright  Copyright (c) 2009-2010 Minh.Shu@gmail.com
 * @license    New BSD License
 * @author     Minh.Shu
 * @version    $Id: Comment.php 2 2010-01-17 13:49:08Z Minh.Shu $
 *
 */

class Domain_DataMapper_Comment extends Domain_DataMapper_Abstract
{
    protected $_tableClassName = 'Domain_Table_Comment';

    protected $_dataMapper = array (
            'commentId' => 'comment_id',
            'articleId' => 'article_id',
            'nickname'  => 'nickname',
            'avatar'    => 'avatar',
            'comment'   => 'comment',
            'replyTime' => 'reply_time',
            'ip'        => 'ip'
    );

    /**
     * 根据文章ID查询评论
     * @param integer $articleId
     * @return object|void
     */
    public function findCommentByArticle($articleId)
    {
        return $this->findAll($this->findCommentByArticleStatement($articleId));
    }

    /**
     * 查询全部评论
     * @return object|void
     */
    public function findAllComment()
    {
        return $this->findAll($this->findAllCommentStatement());
    }


    /**
     * 封装根据文章ID查询评论SQL对象
     * @param integer $articleId
     * @return Zend_Db_Table_Select
     */
    private function findCommentByArticleStatement($articleId)
    {
        $select = $this->getTable()->select();
        $select->where('article_id = ?',$articleId)
                ->order('reply_time DESC');
        return $select;
    }

    /**
     * 封装查询全部评论SQL对象
     * @return Zend_Db_Table_Select
     */
    private function findAllCommentStatement()
    {
        $select = $this->getTable()->select();
        $select->order('comment_id DESC');
        return $select;
    }
}